package cn.edu.scau.cmi.xiaozecheng.adapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiao
 * @date 2019/10/14/014 4:13 PM
 */
public class ObjectAdapter implements Sort {
    @Override
    public List<Student> sortStudent(List<Student> studentList) {
        List<Integer> list = new ArrayList<>(studentList.size());
        for (Student stu : studentList) {
            list.add(stu.getId());
        }
        //类适配器
        SortUtil sortUtil = new SortUtil();
        List<Integer> ascResult = sortUtil.sortInt(list);
        List<Student> result = new ArrayList<>(studentList.size());
        for (Integer integer : ascResult) {
            for (Student student : studentList) {
                if (integer.equals(student.getId())) {
                    result.add(student);
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student(1, "1"));
        list.add(new Student(3, "3"));
        list.add(new Student(2, "2"));
        list.add(new Student(0, "0"));
        List<Student> resultList = new ClassAdapter().sortStudent(list);
        System.out.println(resultList);
    }
}
